package com.bone.util;

import java.math.BigDecimal;

public class PriceUtil {

	/**
	 * 把钱转换成分
	 * @param price
	 * @return
	 */
	public static long convertToFen(float price){
		return (long)(price*100);
	}
	
	public static long convertToFen(BigDecimal price){
		return price.multiply(new BigDecimal(100)).longValue();
	}	
	
	public static float convertToYuan(final Long price){
		if(price==null){
			return 0f;
		}
		BigDecimal p = new BigDecimal(price);
		return p.divide(new BigDecimal(100),2,BigDecimal.ROUND_UP).floatValue();
	}

	
	/**
	 * 把字符串钱转换成分
	 * @param price
	 * @return
	 */
	public static long moneyConvertLongPrice(String price){
		return PriceUtil.convertToFen(new Long(price));
	}
	
	public static long moneyConvertLongPriceLong(Long price){
		return PriceUtil.convertToFen(new Long(price));
	}
	
	public static String moneyConvertStr(long price){
		BigDecimal bigDecimal = new BigDecimal(price);
		return (bigDecimal.floatValue()/100)+"";
	}
 
	
	public static void  main(String[] age){
		float d = 1211.02f*100;
 	}
}
